package com.cykj.page01.servlet;

import com.alibaba.fastjson2.JSON;
import com.cykj.page01.MyHttpRequest;
import com.cykj.page01.MyHttpResponse;
import com.cykj.page01.dto.ResponseDTO;
import com.cykj.page01.service.impl.UserServiceImpl;

/**
 * @BelongsProject: MyTomcat
 * @BelongsPackage: com.cykj.page01.servlet
 * @Author: WWJ
 * @CreateTime: 2025-07-08 10:44
 * @Description: TODO
 * @Version: 1.0
 */
public class EnrollServlet extends BaseServlet{
    @Override
    public void doGet(MyHttpRequest httpRequest, MyHttpResponse httpResponse) {
        doPost(httpRequest, httpResponse);

    }
    @Override
    public void doPost(MyHttpRequest httpRequest, MyHttpResponse httpResponse) {
        String acc = httpRequest.getRequestParamToKey("account");
        String pwd = httpRequest.getRequestParamToKey("password");
        String name = httpRequest.getRequestParamToKey("name");
        //创建用户服务的实体类对象，用于注册逻辑
        UserServiceImpl userService = new UserServiceImpl();
        ResponseDTO dto = userService.enroll(acc, pwd, name);
        httpResponse.write(JSON.toJSONBytes(dto));
    }
}
